<template>
  <div class="container contract-review mb70">
    <p class="bread">
      <a href="#/index/tm-order-list" class="font-s-18">交易监控订单管理-监控师</a> >
      <a href="javascript:void(0);" class="font-s-16">详情</a>
    </p>
    <div class="bg-c-fff box-border">
      <h3 class="tm-title">交易监控订单详情</h3>
      <step :stepData="stepData" :stepNum="stepNum" @stepRouter="stepRouter"></step>
    </div>
    <div class="content bg-c-fff">
      <div class="surveillance-title-box">
        <div class="surveillance-title">交易监控流程图</div>
        <div class="btn-box" v-if="jurisdicType">
          <button type="button" class="white-button" @click="errShow=true">纠错申请</button>
        </div>
      </div>
      <div class="events-box">
        <company-name-container :companyNames="companyNames"></company-name-container>
        <div class="line" :class="{center: companyNames.length===2}" :style="{height: (events.length+0.5)*90+60+'px'}" v-show="events.length">
          <div class="arrow"></div>
        </div>
        <event-item v-for="(item,index) in events" :key="index" :state="item.state" :totalSides="companyNames.length" :side="item.side" :content="item.content" :files="item.files" :isCheck="true"></event-item>
      </div>
      <div class="remark-box" v-if="remark">
        <h4>备注：</h4>
        <div class="remark-text">
          {{remark}}
        </div>
      </div>
    </div>
    <vodal :show="errShow" animation="zoom" :width="370" :height="210" @hide="errShow=false">
      <div class="vodal-main">
        <h4>纠错申请</h4>
        <div class="con">
          <p>备注信息：
            <textarea class="vt" v-model="errorContent">
            </textarea>
          </p>
          <div class="auto tc">
            <button class="blue-button xl-btn-css" @click="onErrorSubmit">确认</button>
            <button class="blue-button xl-btn-css" @click="errShow=false">取消</button>
          </div>
        </div>
      </div>
    </vodal>
  </div>
</template>
<script type="text/javascript">
import Step from '../components/Step'
import CompanyNameContainer from '../components/CompanyNameContainer'
import EventItem from '../components/EventItem'
export default {
  components: {
    Step,
    CompanyNameContainer,
    EventItem
  },
  data() {
    return {
      id: '',
      stepNum: 3,
      stepData: [{
        name: '查看资质审查报告'
      }, {
        name: '审查合同'
      }, {
        name: '绘制流程图'
      }, {
        name: '绘制完成'
      }],
      companyNames: [],
      events: [],
      remark: '',
      status: '',
      errShow: false,
      jurisdicType: true,
      errorContent: ''
    }
  },
  mounted() {
    this.id = this.$route.query.id
    this.getData()
  },
  methods: {
    getData() {
      this.$http.post('/transactionMonitorSer/sys/read/detail', {
        id: this.id
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.remark = data.data.data.remark
          this.status = data.data.data.status
          if (this.status >= 6) {
            this.jurisdicType = false
          }
          data.data.data.eventList.forEach(item => {
            let event = {}
            event.content = item.content
            event.side = item.memberOrder
            event.state = item.status
            event.files = item.fileList || []
            event.index = item.order
            event.id = item.id
            this.events.push(event)
          })
          data.data.data.memberList.forEach(member => {
            this.companyNames.push({
              name: member.memberName,
              id: member.id
            })
          })
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    stepRouter(i, name) {
      if (i === 0 && this.status >= 2) {
        this.$router.push('/tm-transaction-aptitude?id=' + this.$route.query.id)
      }
      if (i === 1 && this.status >= 3) {
        this.$router.push('/tm-transaction-contract?id=' + this.$route.query.id)
      }
      if (i === 2 && this.status > 4) {
        this.$toasted.show('请查看绘制完成图')
      }
      if (i === 2 && this.status === 4) {
        this.$router.push('/tm-transaction-draw?id=' + this.$route.query.id)
      }
      if (i === 3 && this.status >= 5) {
        this.$router.push('/tm-transaction-draw-finish?id=' + this.$route.query.id)
      }
    },
    onErrorSubmit() {
      if (!this.errorContent) {
        this.$toasted.show('内容不能为空')
        return
      }
      this.$http.post('/tradeError/send/trade/error', {
        orderid: this.id,
        recivedType: 2,
        errorContent: this.errorContent
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$toasted.show('发送成功')
          this.errShow = false
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    }
  }
}

</script>
<style type="text/css" scoped>
.content {
  margin-top: 20px;
}

.surveillance-title-box {
  position: relative;
  width: 100%;
  height: 40px;
  line-height: 40px;
  margin-top: 20px;
  border-bottom: 1px solid #ddd;
  background-color: #fff;
  text-align: center;
}

.surveillance-title {
  font-size: 14px;
  color: #282828;
}

.surveillance-title-box .btn-box {
  position: absolute;
  top: 0;
  right: 100px;
  font-size: 14px;
}

.surveillance-title-box .white-button {
  width: 100px;
  height: 30px;
  line-height: 30px;
  margin-left: 10px;
}

.remark-box {
  padding: 30px;
}

.remark-box h4 {
  font-size: 20px;
}

.remark-box .remark-text {
  margin-top: 10px;
  font-size: 18px;
}

.line {
  position: absolute;
  width: 2px;
  top: 0;
  left: 65px;
  margin-top: 10px;
  background-color: #cfcfcf;
}

.line.center {
  left: 50%;
}

.line .arrow {
  position: absolute;
  bottom: -10px;
  left: -7px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 12px solid #cfcfcf;
}

.events-box {
  position: relative;
  padding-bottom: 60px;
  overflow-x: auto;
}

.vodal-main .con button {
  margin: 15px 10px 0 10px;
}

textarea {
  width: 250px;
  height: 80px;
}

</style>
